package com.example.mobile2021606163crw0516;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.List;

public class ViewPageAdapter extends FragmentStateAdapter {
    //定义Fragment的集合类对象，并在构造方法中进行初始化
    List<Fragment> fragmentList;
//    public ViewPageAdapter(@NonNull  FragmentManager fragmentManager, Lifecycle lifecycle, List<Fragment> fragmentList) {
//        super(fragmentManager,lifecycle);
//        this.fragmentList = fragmentList;
//    }
    public ViewPageAdapter(FragmentManager fragmentManager, Lifecycle lifecycle, List<Fragment> fragmentList){
        super(fragmentManager,lifecycle);
        this.fragmentList = fragmentList;

    }
    //重写两个方法
    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getItemCount() {
        return fragmentList.size();
    }
}